package org.csu.onlineedubackend.task;

import org.csu.onlineedubackend.mapper.LogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class LogCleanupTask {

    @Autowired
    private LogMapper logMapper;

    /**
     * 每天凌晨3点清理超过14天的日志
     */
    @Scheduled(cron = "0 0 3 * * ?")
    public void clearOldLogs() {
        LocalDateTime cutoff = LocalDateTime.now().minusDays(14);
        int deleted = logMapper.deleteLogsBefore(cutoff);
        System.out.println("🧹 定时清理日志：删除了 " + deleted + " 条记录，截止时间：" + cutoff);
    }
}
